export function request(url, data = {}, method = 'get', heardType = 'JSON') {
	const accessToken = uni.getStorageSync('accessToken') || null;
	let header = {}
	if (accessToken) {
		header = {
			Authorization: accessToken
		}
	}
	return new Promise((resolve, reject) => {
		uni.showLoading({
			title: '正在加载'
		});
		uni.request({
			url: 'https://upubio.com/shop-web/' + url,
			data,
			header: header,
			method,
			firstIpv4: true,
			success(result) {
				uni.hideLoading()
				if (result.statusCode == 200) {
					resolve(result.data);
				} else {
					if (result.statusCode == 401) {
						uni.showToast({
							title: result.data.error.message,
							icon: 'none',
							duration: 2000
						});
						uni.removeStorage({
							key: 'accessToken'
						})
						uni.redirectTo({
							url: '/pages/login/login'
						});

						return
					}

					uni.showToast({
						title: result.data.error.message,
						icon: 'none',
						duration: 2000
					});
					reject(result)
				}
			},
			fail(err) {
				console.log('请求失败', err)
				reject(err)
			}
		})
	})
}